local yufeng = fk.CreateSkill{
    name = "ym_water__yufeng"
}
Fk:loadTranslationTable{
    ["ym_water__yufeng"] = "御风",
    [":ym_water__yufeng"] = "出牌阶段限一次，你可以表演“御风飞行”。若表演失败，则你摸X张牌。若表演成功，则你可以选择至多X名其他角色获得“<a href=':ym_water__yufengxiaoguo'>御风</a>”效果，然后摸若选择角色数不足X则多余的分数改为摸牌。（X为御风飞行得分）",
    ["@[desc]ym_water__yufengxiaoguo"] = "御风",
    [":ym_water__yufengxiaoguo"] = "准备阶段开始时，你进行判定。若结果为：红色，你跳过摸牌阶段；黑色，你跳过出牌阶段和弃牌阶段",
    ["#ym_water__yufeng-prompt"] = "你可玩一次小游戏，成功后令他人跳过摸牌或出牌弃牌阶段",
    ["#ym_water__yufeng-choose"] = "御风: 选择至多 %arg 名其他角色，其下回合跳过摸牌或出牌弃牌阶段",

    ["$ym_water__yufeng1"] = "广开兮天门，纷吾乘兮玄云。",
    ["$ym_water__yufeng2"] = "高飞兮安翔，乘清气兮御阴阳。",
}
Fk:addMiniGame{
  name = "ym_water__yufeng",
  qml_path = "packages/water_wegame/qml/yufeng",
  default_choice = function(player, data)
    return "false,0"
  end,
  update_func = function(player, data)
    local room = player.room
    if #data == 1 and data[1] == "confirm" then
        for _, p in ipairs(room:getOtherPlayers(player, false)) do
            p:doNotify("UpdateMiniGame", "")
        end
    else
        local dat = table.concat(data, ",")
        local success, syncData = pcall(json.decode, string.sub(dat, string.find(dat, ",", 1, true) + 1))
        if success and syncData.type then
            if syncData.type == "jump" then
                player.room:broadcastPlaySound("./packages/water_wegame/image/anim/yufeng/yufeng_fly")
            elseif syncData.type == "star-collected" then
                player.room:broadcastPlaySound("./packages/water_wegame/image/anim/yufeng/yufeng_getStar")
            elseif syncData.type == "game-end" then
                player.client_reply = tostring(syncData.win)..","..tostring(syncData.score)
                if syncData.win and syncData.score > 0 then
                    player.room:broadcastPlaySound("./packages/water_wegame/image/anim/yufeng/yufeng_win")
                else
                    player.room:broadcastPlaySound("./packages/water_wegame/image/anim/yufeng/yufeng_fail")
                end
            end
        end
        for _, p in ipairs(room:getOtherPlayers(player, false)) do
            p:doNotify("UpdateMiniGame", dat)
        end
    end
  end,
}
yufeng:addEffect("active",{
    prompt = "#ym_water__yufeng-prompt",
    max_phase_use_time = 1,
    can_use = function (self, player)
        return self:withinTimesLimit(player,Player.HistoryPhase)
    end,
    card_num = 0,
    target_num = 0,
    card_filter = Util.FalseFunc,
    target_filter = Util.FalseFunc,
    on_use = function (self, room, effect)
        local player = effect.from
        local data_table = {}
        for _, p in ipairs(room.players) do
            data_table[p.id] = {
                p == player,
            }
        end
        room:askToMiniGame(room.players, {
            skill_name = yufeng.name,
            game_type = "ym_water__yufeng",
            data_table = data_table
        })
        local data = player.client_reply:split(",")
        if #data > 0 then
            local gameWin = data[1]
            local score = tonumber(data[2])
            if gameWin == "true" then
                local tos = player.room:askToChoosePlayers(player, {
                    targets = room:getOtherPlayers(player, false),
                    min_num = 1,
                    max_num = score,
                    prompt = "#ym_water__yufeng-choose:::" .. score,
                    skill_name = yufeng.name,
                    cancelable = true,
                })
                if #tos > 0 then
                    for _, p in ipairs(tos) do
                        room:setPlayerMark(p, "@[desc]ym_water__yufengxiaoguo", 1)
                    end
                end
                score = score - #tos
            end
            if score > 0 then
                player:drawCards(score, yufeng.name)
            end
        end
    end,
})
yufeng:addEffect(fk.EventPhaseStart, {
    anim_type = "negative",
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        return target == player and player.phase == Player.Start and player:getMark("@[desc]ym_water__yufengxiaoguo") > 0
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player, "@[desc]ym_water__yufengxiaoguo", 0)
        local judge = {
            who = player,
            reason = yufeng.name,
            pattern = ".",
        }
        room:judge(judge)
        if judge.card.color == Card.Black then
            player:skip(Player.Play)
            player:skip(Player.Discard)
        elseif judge.card.color == Card.Red then
            player:skip(Player.Draw)
        end
    end,
})
return yufeng